466A - Cheap Travel - CodeForces Solution


implementation *1200

Please click on ads to support us..

Python Code:

n, m, a, b = list(map(int, input().split()))
if b >= m*a:
    print(n*a)
else:
    print(min((n//m)*b + n % m*a, ((n+m-1)//m)*b))

C++ Code:

#include<bits/stdc++.h>
using namespace std;

#define ll long long 

void solve(){
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	int div=b/m;
	int rem=b%m;
	if(div>=a){
		cout<<n*a<<endl;
	}
	else if(div<a){
		int ans=b*(n/m)+min((n%m)*a,b);
		cout<<ans<<endl;
	}
	
}
 
int main(){
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}
}


Comments

Submit
0 Comments
More Questions

9C - Hexadecimal's Numbers
1265B - Beautiful Numbers
745A - Hongcow Learns the Cyclic Shift
873A - Chores
1754B - Kevin and Permutation
1547D - Co-growing Sequence
1754D - Factorial Divisibility
1117B - Emotes
412B - Network Configuration
845B - Luba And The Ticket
1732A - Bestie
389A - Fox and Number Game
1732B - Ugu
1100B - Build a Contest
1181B - Split a Number
1313B - Different Rules
1736D - Equal Binary Subsequences
1754A - Technical Support
26B - Regular Bracket Sequence
699A - Launch of Collider
474D - Flowers
1016A - Death Note
1335C - Two Teams Composing
1167C - News Distribution
813C - The Tag Game
1130C - Connect
1236B - Alice and the List of Presents
845C - Two TVs
1144D - Equalize Them All
298A - Snow Footprints